package com.spi.soconversion.base.definition;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.spi.soconversion.util.SOCConstants;
import com.spi.soconversion.util.XMLTagConstants;

public class SOCOrderLineTaxes {

	private List<SOCOrderLineTax> lineTaxList = new ArrayList<SOCOrderLineTax>();
	private BigDecimal taxTotal=new BigDecimal("0");
	
	public boolean addLineTax(SOCOrderLineTax on){
		boolean status = false;
		if(!lineTaxList.contains(on)) {
			status = lineTaxList.add(on);
		}
		
		return status;
	}
	
	public boolean removeLineTax(SOCOrderLineTax on){
		boolean status = false;
		status = lineTaxList.remove(on);
				
		return status;
	}

	public List<SOCOrderLineTax> getLineTaxList(){
		return lineTaxList;		
	}
	
	@Override
	public String toString()
	{
		StringBuilder sb = new StringBuilder();
		
		if(lineTaxList!=null && lineTaxList.size()>0)
		{
			sb.append(XMLTagConstants.START_TAG_LINE_TAXES);
			Iterator<SOCOrderLineTax> iter=lineTaxList.iterator();			
			while(iter.hasNext())
	    	{
    			SOCOrderLineTax lineTax=iter.next();    			
    			sb.append(SOCConstants.NEW_LINE);
    			sb.append(lineTax.toString());  
			}
    		sb.append(SOCConstants.NEW_LINE);
    		sb.append(XMLTagConstants.END_TAG_LINE_TAXES);
    		
		}
		
		return sb.toString();
	}
	
	public BigDecimal getTaxTotal()
	{
		taxTotal=new BigDecimal("0");
		if(lineTaxList!=null && lineTaxList.size()>0)
		{
			Iterator<SOCOrderLineTax> iter=lineTaxList.iterator();			
			while(iter.hasNext())
	    	{
    			SOCOrderLineTax lineTax=iter.next();    		
    			taxTotal = taxTotal.add(lineTax.getTaxAmount());   
			}
		}
		return taxTotal;
	}	
}
